package Work.Thread;

import com.wyt.lzzy.Student;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class TestThread {
    public static void main(String[] args) throws Exception {
        Students stu1 = new Students(11,"张三",19);
        Students stu2 = new Students(12,"李四",20);
        Students stu3 = new Students(13,"王五",21);
        List<Students> list = new ArrayList<Students>();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        Runnable printA = new PrintChar("你好！", 50);
        Printstus printstus = new Printstus(list);
        Runnable printB = new PrintChar("再见！", 50);

        Thread thread1 = new Thread(printA);
        Thread thread2 = new Thread(printstus);
        Thread thread3 = new Thread(printB);

        thread1.start();
        thread2.start();
        thread3.start();
    }
}

class PrintChar implements Runnable {
    private String charToPrint; // The character to print
    private int times; // The times to repeat

    public PrintChar(String c, int t) {
        charToPrint = c;
        times = t;
    }

    @Override
    public void run() {
        for (int i = 0; i < times; i++) {
            System.out.println(charToPrint);
        }
    }
}

class Printstus implements Runnable{
    private List stus;

    public Printstus(List stus) {
        this.stus = stus;
    }

    @Override
    public void run() {
        stus.forEach(x -> System.out.println(x));
    }


}